package admin;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;


public class getBlogData {
	private List<Blog> list=new ArrayList<Blog>();
	public List<Blog> getData() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Getconfig gc=new Getconfig();
			String url= gc.getParaValue("connectUrl");
			Connection conn=DriverManager.getConnection(url);
			String sql="select * from blogdata";
			PreparedStatement ps=conn.prepareStatement(sql);
			ResultSet rs=ps.executeQuery();
			while(rs.next()) {
				int id=rs.getInt("id");
				String title=rs.getString("blogtitle");	
				String desribe=rs.getString("blogdescribe");	
				String author=rs.getString("blogauthor");
				String time=rs.getString("starttime");
				String cover=rs.getString("blogcoverurl");
				String dataurl=rs.getString("blogdata");
				
				Blog b=new Blog();
				b.setId(id);
				b.setTitle(title);
				b.setDesribe(desribe);
				b.setAuthor(author);
				b.setTime(time);
				b.setCoverurl(cover);
				b.setDataurl(dataurl);
				list.add(b);
				}
			ps.close();
			conn.close();
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return list;
	}
//
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub
//		getBlogData ggg=new getBlogData();
//		System.out.println(ggg.getData());
//	}

}
